package com.cskaoyan.controller.advertising;

import com.cskaoyan.bean.bo.AdminAdCreateBo;
import com.cskaoyan.bean.bo.AdminAdDeleteBo;
import com.cskaoyan.bean.bo.AdminAdUpdateBo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.AdminAdCreateVo;
import com.cskaoyan.bean.vo.AdminAdListVo;
import com.cskaoyan.bean.vo.AdminAdUpdateVo;
import com.cskaoyan.service.AdvertisingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/ad")
public class AdvertisingAdController {
    @Autowired
    AdvertisingService advertisingService;
    /***
     * 获取广告管理表
     * /admin/ad/list
     */
    @GetMapping("list")
    public BaseRespVo getAdvertisingList(Integer page,Integer limit,String name,String content,String sort,String order){
        AdminAdListVo adminAdListVo = advertisingService.getOrderAdList(page,limit,name,content,sort,order);
        return BaseRespVo.ok(adminAdListVo);
    }

    /**
     * @Description: 新增广告
     * @Description: /admin/ad/create
     * @date: 2022/9/6 21:34
     * @author: zyc
     */
    @PostMapping("create")
    public BaseRespVo addNewAdvertising(@RequestBody AdminAdCreateBo createBo){
        AdminAdCreateVo createVo = advertisingService.createAdvertising(createBo);
        return BaseRespVo.ok(createVo);
    }

    /**
     * @Description: 更新广告信息
     * @Description: /admin/ad/update
     * @date: 2022/9/6 22:07
     * @author: zyc
     */
    @PostMapping("update")
    public BaseRespVo updateAdvertising(@RequestBody AdminAdUpdateBo updateBo){
        AdminAdUpdateVo updateVo = advertisingService.updateAdvertising(updateBo);
        return BaseRespVo.ok(updateVo);
    }

    /**
     * @Description: 删除广告信息
     * @Description: /admin/ad/delete
     * @date: 2022/9/7 9:25
     * @author: zyc
     * @since JDK 1.8
     */
    @PostMapping("delete")
    public BaseRespVo deleteAdvertising(@RequestBody AdminAdDeleteBo deleteBo){
        advertisingService.deleteAdvertising(deleteBo);
        return BaseRespVo.ok("成功");
    }
}
